package com.yao_shop.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;

import java.io.FileWriter;
import java.io.IOException;


@RestController
public class Template_bookController {

    @Autowired
    private SpringTemplateEngine templateEngine;
    @ResponseBody
    @RequestMapping("/aaa")
    public void testFreemarker() throws IOException {
        //构造上下文(Model)
        Context context = new Context();
        context.setVariable("name", "李四");
        context.setVariable("content", "<p><strong>tes&nbsp;</strong></p>\n" +
                "<p><img alt=\"\" class=\"has\" height=\"189\" src=\"http://127.0.0.1:8080/image/QQ图片20190405221955.jpg\" width=\"256\" />");
        FileWriter fileWriter = new FileWriter("//templates//");
        templateEngine.process("Template_book",context,fileWriter);

    }
}
